package
{
	import com.ascainiao3d.display.Cube3D;
	import com.ascainiao3d.display.World3D;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	[SWF(width=800,height=600,backgroundColor=0xffffff,frameRate=30)]
	public class TwoCubeTest extends Sprite
	{
		private var cube0:Cube3D;
		private var cube1:Cube3D;
		private var cube2:Cube3D;
		private var world:World3D;
		private var _vpx:Number;
		private var _vpy:Number;
		private var clickX:Number;
		private var clickY:Number;
		public function TwoCubeTest()
		{
			_vpx=stage.stageWidth / 2;
			_vpy=stage.stageHeight / 2;
			
			world=new World3D(_vpx,_vpy);
			addChild(world);
			
			cube0=new Cube3D(100,0xff0000);
			cube0.setPosition(0,-100,0);
			world.addObject3D(cube0);
			
			cube1=new Cube3D(100,0x00ff00);
			cube1.setPosition(0,0,0);
			world.addObject3D(cube1);
			
			cube2=new Cube3D(100,0x0000ff);
			cube2.setPosition(0,100,0);
			world.addObject3D(cube2);
			
			//world.light=
			world.rendering();
			
			stage.addEventListener(MouseEvent.MOUSE_DOWN,onStageDown);
			stage.addEventListener(MouseEvent.MOUSE_UP,onStageUp);
		}
		
		private function onStageDown(e:MouseEvent):void{
			cube0.snapshot();
			cube1.snapshot();
			cube2.snapshot();
			clickX=mouseX;
			clickY=mouseY;
			//trace(cube0.z,cube1.z,cube2.z);
			this.addEventListener(Event.ENTER_FRAME,onEnterFrame);
		}
		private function onStageUp(e:MouseEvent):void{
			this.removeEventListener(Event.ENTER_FRAME,onEnterFrame);
		}
		private function onEnterFrame(event:Event):void
		{
			var angleX:Number = (mouseY - clickY) * .3;
			var angleY:Number = (mouseX - clickX) * .3;
			cube0.rotationXY(angleX,angleY);
			cube1.rotationXY(angleX,angleY);
			cube2.rotationXY(angleX,angleY);
			world.rendering();
		}
	}
}